<?php
use \Common\Model\Cate;
    	//取分类数据
    	$cateModel=new Cate();
		$cateData=$cateModel->where("pid=0")->get();
		//压入二级分类
		foreach($cateData as $k=>$c){
			$cateData[$k]['secondary']=$cateModel->where("pid={$c['cid']}")->get();
		}
		//压入三级分类
		foreach($cateData as $k=>$c){
			if(empty($cateData[$k]['secondary'])) continue;//判断二级分类是否存在
			foreach($cateData[$k]['secondary'] as $kk=>$v){
				$cateData[$k]['secondary'][$kk]['son']=$cateModel->where("pid={$v['cid']}")->get();
			}
		}
		View::with('cateData',$cateData);
	//购物车
	$count = Cart::getTotalNums();  
	if(empty($count)){
		$count=0;
	}
	
	//用户名
	use \Home\Model\User;
	if(isset($_SESSION['user'])){
		$userModel = new User();
		$uid = $_SESSION['user']['uid'];
		$userData = $userModel->where("uid={$uid}")->find();
	}

?>	
		<!--灰色区块-->
		<div id="heard_top">
			<div class="heard_body">
				
				<div class="heard_body_right">
					<div class="ddnewhead_welcome">
						<span class="welcome">欢迎光临当当,</span>
						{{if value="isset($_SESSION['user'])"}}
							<a href="{{U('Order/index')}}">{{$userData['account']}}</a><a href="{{U('Member/out')}}">[退出]</a>
						{{endif}}
						{{if value="empty($_SESSION['user'])"}}
							请<a target="_blank" href="{{U('Login/index')}}" class="denglu">登录</a>
							<a target="_blank" href="{{U('Member/reg')}}">成为会员</a>
						{{endif}}
					</div>
					<ul class="ddnewhead_operate_nav">
						<li>
							{{if value="!isset($count)"}}
								<a href="{{U('Cart/noCart')}}" class="cart">购物车</a>
							{{else}}
								<a href="{{U('Cart/index')}}" class="cart">购物车</a>
							{{endif}}
							
						</li>
						<li>
							{{if value="isset($_SESSION['user'])"}}
								<a href="{{U('Order/index')}}">我的订单</a>
							{{else}}
								<a href="{{U('Login/index')}}">我的订单</a>	
							{{endif}}



						</li>
							</ul>
						</li>
				</ul>
				</div>
			</div>
		</div>
		<!--灰色区块结束-->
		<!--logo搜索区块-->
		<div id="logo">
			<div class="logo-quk">
				<div class="logo_left">
					<a href="index.php"><img src="./Public/Home/images/0.gif"/></a>
				</div>
				<div class="logo_middle">
					<form action="{{U('ListPage/index')}}" method="get">
						<input type="text" name="key" placeholder="温州特产善味阁鸭舌头 香辣酱鸭舌独立小包8~12g 零食" class="cl" style="visibility: visible";/>
						<div class="select"><span>全部分类</span></div>
						<input type="hidden" name="default_key" class="default_key" value="温州特产善味阁鸭舌头 香辣酱鸭舌独立小包8~12g 零食" />
						<script type="text/javascript">
							$(function(){
								$(".cl2").click(function(){
									var key =  $(".cl").val();
									var default_key = $(".default_key").val();
										if(key != ''){
											location.href="{{U('ListPage/search')}}" + '&k=' + key;
										}else{
											location.href="{{U('ListPage/search')}}" + '&k=' + default_key;
										}
								})
								
								$(document).keyup(function(event){
									if(event.keyCode ==13){
										$(".cl2").trigger("click");
									}
								});
								
							})
						</script>
						<input type="button" class="cl2" value=""/>
						
					</form>
				</div>
				<div class="logo_right">
					<div class="logo_gouwu">
						{{if value="!isset($count)"}}
							<a href="{{U('Cart/noCart')}}" class="cart">购物车</a>
						{{else}}
							<a href="{{U('Cart/index')}}" class="cart">购物车</a>
						{{endif}}
					</div>
					<div class="logo_dt">
						{{if value="isset($_SESSION['user'])"}}
							<a href="{{U('Order/index')}}">我的订单</a>
						{{else}}
							<a href="{{U('Login/index')}}">我的订单</a>
						{{endif}}
						
					</div>
				</div>
				
			</div>
		</div>
		<!--导航栏-->
		<div id="dh">
			<div class="dh_class">
				<div class="classify">
					<a href="index.php" class="dh_fl">全部商品分类</a>
					<ul class="box">
						{{foreach from="$cateData" value='$v'}}
						<li class="menu_one">
							<a href="" class="oi">{{$v['cname']}}</a>
							<!--菜单栏里面的子菜单-->
								<div class="submenu">
									<div class="boxs">
										<div class="submenu_one">
											<a href="{{U('ListPage/index',["cid"=>$v['cid']])}}">{{$v['cname']}}</a>
										</div>
										{{foreach from="$v['secondary']" value="$u"}}
											<ul class="submenu_two">
													<a href="{{U('ListPage/index',["cid"=>$v['cid']])}}"><h4>{{$u['cname']}}</h4></a>
													<li >
														{{foreach from="$u['son']" value="$s"}}
															<a href="{{U('ListPage/index',["cid"=>$v['cid']])}}">{{$s['cname']}}</a>
														{{endforeach}}
													</li>
											</ul>
										{{endforeach}}
									</div>
								</div>
							<!--菜单栏里面的子菜单结束-->
						</li>
						{{endforeach}}

					</ul>
				</div>
				
				<!--顶级分类-->
				<ul class="ban">
					{{foreach from="$cateData" value="$v"}}
					<li class="children">
						<a href="{{U('ListPage/index',["cid"=>$v['cid']])}}">{{$v['cname']}}</a>
					</li>
					{{endforeach}}
				</ul>
			</div>
		</div>
		<!--导航栏结束-->